package com.atguigu.lease.web.app.service.impl;

import com.atguigu.lease.model.entity.ApartmentInfo;
import com.atguigu.lease.model.enums.ItemType;
import com.atguigu.lease.web.app.mapper.*;
import com.atguigu.lease.web.app.service.ApartmentInfoService;
import com.atguigu.lease.web.app.vo.apartment.ApartmentDetailVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @author liubo
 * @description 针对表【apartment_info(公寓信息表)】的数据库操作Service实现
 * @createDate 2023-07-26 11:12:39
 */
@Service
public class ApartmentInfoServiceImpl extends ServiceImpl<ApartmentInfoMapper, ApartmentInfo>
        implements ApartmentInfoService {

    @Autowired
    private GraphInfoMapper graphInfoMapper;
    @Autowired
    private RoomInfoMapper roomInfoMapper;
    @Autowired
    private ApartmentLabelMapper apartmentLabelMapper;
    @Autowired
    private ApartmentFacilityMapper apartmentFacilityMapper;

    @Override
    public ApartmentDetailVo getApartmentDetailById(Long id) {

//公寓
        ApartmentInfo apartmentInfo = this.getById(id);
        if(ObjectUtils.isEmpty(apartmentInfo)){
            return null;
        }
        ApartmentDetailVo apartmentDetailVo=new ApartmentDetailVo();
        apartmentDetailVo.setGraphVoList(graphInfoMapper.graphListByItemId(id,ItemType.APARTMENT));
        apartmentDetailVo.setLabelInfoList(apartmentLabelMapper.queryListByApartmentId(id));
        apartmentDetailVo.setFacilityInfoList(apartmentFacilityMapper.queryListByApartmentId(id));
        apartmentDetailVo.setMinRent(roomInfoMapper.getminRentByApartId(id));
        apartmentDetailVo.setIsDelete(apartmentInfo.getIsDeleted()==1);
        BeanUtils.copyProperties(apartmentInfo,apartmentDetailVo);
        return apartmentDetailVo;
    }
}




